package com.hl.card.modular.pack.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.hl.card.common.persistence.dao.BibivipRecordMapper;
import com.hl.card.common.persistence.model.BibivipRecord;
import com.hl.card.common.persistence.model.Recharge;
import com.hl.card.modular.pack.service.IBibivipRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * <p>
 * 航空vip申请记录 服务实现类
 * </p>
 *
 * @author coole
 * @since 2018-09-21
 */
@Service
public class BibivipRecordServiceImpl extends ServiceImpl<BibivipRecordMapper, BibivipRecord> implements IBibivipRecordService {

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @Override
    public BibivipRecord getRedisRecord(String userId) {
        String   rechageStr=  redisTemplate.opsForValue().get("bibivipRecord"+userId);
        return JSONObject.parseObject(rechageStr, BibivipRecord.class);
    }
    
    @Override
    public String saveToRedis(BibivipRecord order) {
        String jsonStr=JSONObject.toJSONString(order);
        redisTemplate.opsForValue().set("bibivipRecord"+order.getUserid(),jsonStr,15, TimeUnit.MINUTES);
        return jsonStr;
    }

}
